#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：HiflyVideoAPI_Test 
@File    ：vo.py
@Author  ：beibei
@Date    ：2025/6/10 10:58 AM 
'''
import requests
from common.caseOutput import info, error, case


class BusinessRe:
    @staticmethod
    def post(url, Authorization, body, headers=None, **kwargs):
        if headers is None:
            headers = {
                'authorization': f'{Authorization}',
                'Content-Type': 'application/json'
            }

        info(f'request url: {url}')
        info(f'request headers: {headers}')
        info(f'request body: {body}')
        try:
            res = requests.post(url, headers=headers, json=body, **kwargs)
        except TimeoutError:
            error(f'url: {url}, requests timeout！')
            return 'Requests Timeout!'
        info(f'response code: {res.status_code}')
        info(f'response body: {res.text}')
        return res

    @staticmethod
    def get(url, Authorization, params=None, headers=None):
        if headers is None:
            headers = {
                'authorization': f'{Authorization}',
                'Content-Type': 'application/json'
            }

        info(f'request url: {url}')
        info(f'request headers: {headers}')
        if params:
            info(f'request params: {params}')

        try:
            res = requests.get(url, headers=headers, params=params, timeout=5)
        except requests.exceptions.Timeout:
            error(f'url: {url}, requests timeout！')
            return 'Requests Timeout!'
        except Exception as e:
            error(f'url: {url}, unexpected error: {e}')
            return f'Error: {e}'

        info(f'response code: {res.status_code}')
        info(f'response body: {res.text}')
        return res